package com.team.arms.public_data.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.team.arms.common.PageVO;
import com.team.arms.common.annotation.Log;
import com.team.arms.common.ry.core.controller.BaseController;
import com.team.arms.common.ry.core.domain.AjaxResult;
import com.team.arms.common.ry.enums.BusinessType;
import com.team.arms.public_data.domain.SoldierInformation;
import com.team.arms.public_data.service.SoldierInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yjh
 * @create 2022-05-18-20:13
 * @description:
 */
@Api( tags = "兵种信息")
@RestController
@RequestMapping("/publicDate/SoldierInformation")
public class    SoldierInformationController extends BaseController {

    @Autowired
    private SoldierInformationService soldierInformationService;

    /**
     * 查询兵种信息
     * @return
     */
    @ApiOperation("查询兵种信息")
    @GetMapping("/select")
    public AjaxResult selectPage(@ApiParam("选中的页数") @RequestParam("pageNum") Integer pageNum ,
                                    @ApiParam("页面显示的数据量") @RequestParam("pageSize") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<SoldierInformation> list = soldierInformationService.list();
        PageInfo<SoldierInformation> pageInfo = new PageInfo<SoldierInformation>(list);
        PageVO<SoldierInformation> soldierInformationPageVO = new PageVO<>();
        BeanUtils.copyProperties(pageInfo, soldierInformationPageVO);
        soldierInformationPageVO.setResult(pageInfo.getList());
        soldierInformationPageVO.setPage(pageNum);
        return AjaxResult.success(soldierInformationPageVO);
    }

    @ApiOperation("根据id查询兵种信息")
    @GetMapping("/selectById")
    public AjaxResult selectById( @RequestParam(value = "soldier_info_id")String id){
        return AjaxResult.success(soldierInformationService.selectById(id));
    }

    /**
     * 新增兵种信息
     */
    @ApiOperation("新增兵种信息")
    @PostMapping("/install")
    public AjaxResult installInformation(@RequestBody SoldierInformation soldierInformation){
        return toAjax(soldierInformationService.insertAll(soldierInformation));
    }

    /**
     * 修改兵种信息
     */
    @ApiOperation("修改兵种信息")
    @Log(title = "修改兵种信息", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult updateInformation(
            @RequestParam(value = "soldier_info_id")String id,
            @RequestBody SoldierInformation soldierInformation){
        QueryWrapper<SoldierInformation> wrapper = new QueryWrapper();
        wrapper.eq("soldier_info_id",id);
        SoldierInformation soldierInformationServiceById = soldierInformationService.getById(id);
        return toAjax(soldierInformationService.update(soldierInformation,wrapper));
    }
}
